import mongoose from "mongoose";

const torrentSchema = new mongoose.Schema({
  infoHash: {
    type: String,
    required: true,
    unique: true,
  },
  name: {
    type: String,
    required: true,
  },
  size: {
    type: Number,
    required: true,
  },
  category: {
    type: String,
    required: true,
  },
  tags: [String],
  files: [
    {
      path: String,
      size: Number,
    },
  ],
  createdAt: {
    type: Date,
    default: Date.now,
  },
  updatedAt: {
    type: Date,
    default: Date.now,
  },
});

// 更新时自动更新 updatedAt 字段
torrentSchema.pre("save", function (next) {
  this.updatedAt = Date.now();
  next();
});

const Torrent = mongoose.model("Torrent", torrentSchema);

export default Torrent;
